package zhu.areas.match.action;

import java.util.List;

import zhu.areas.match.data.CompApp;
import zhu.areas.match.data.CompResult;
import zhu.areas.match.service.ICompAppService;
import zhu.common.data.Pager;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;
public class ShowCompAction  extends ActionSupport {
	private ICompAppService compAppService;
	
	private List<CompApp> compAppList;
	private List<CompResult> compResultList;
	
	private Pager  compAppPager;
	private Pager  compResultPager;
	private String currentPage;
	private String pageMethod;
	private Integer pageSize=4;//每页显示的记录数目
	private int latestCompPageSize = 4;
	private CompApp compApp;
	private CompResult compResult;
	private int compId;
	
	public String toCompPub() {
		this.clearErrorsAndMessages();
		compResultPager = compAppService.findCompResultAsPager(pageSize, "0","first");  			
		compResultList = compResultPager.getList();
		ServletActionContext.getRequest().getSession().setAttribute("compResultList",compResultList);
		compAppPager = compAppService.queryForPage(5,pageSize, "0","first"); 
		compAppList = compAppPager.getList();
		return SUCCESS;
	}

	public String compPub(){
		compAppPager = compAppService.queryForPage(5,pageSize, currentPage,pageMethod); // 5表示已发布
		compAppList =  compAppPager.getList();
		
		return SUCCESS;
	}
	
	public String toCompAudit() {
		this.clearErrorsAndMessages();
		Object uID = ServletActionContext.getRequest().getSession()
				.getAttribute("userID");
		if (uID == null)
			return INPUT;
		compAppPager = compAppService.queryForPage(1,pageSize, currentPage,pageMethod); // 1表示待审核
		compAppList = (List<CompApp>) compAppPager.getList();
		return SUCCESS;
	}
	
	public String compAudit() {
		compApp = compAppService.findCompAppById(compId);
		// compApp.setStatue(new MatchStatue(2));
		//compAppService.updateCompApp(compApp);
		return SUCCESS;
	}

	public String submitAudit() {
		compAppService.updateCompApp(compApp);
		return SUCCESS;
	}
	
	public String showDetail() {
		compApp = compAppService.findCompAppById(compId);
		System.out.println(compApp.getApplier().getUsername());
		return SUCCESS;
	}
	
	public String showCompResult() {
		compResult=compAppService.findCompResultByID(compId);
		return SUCCESS;
	}
	
	public ICompAppService getCompAppService() {
		return compAppService;
	}

	public void setCompAppService(ICompAppService compAppService) {
		this.compAppService = compAppService;
	}

	public List<CompApp> getCompAppList() {
		return compAppList;
	}

	public void setCompAppList(List<CompApp> compAppList) {
		this.compAppList = compAppList;
	}

	public List<CompResult> getCompResultList() {
		return compResultList;
	}

	public void setCompResultList(List<CompResult> compResultList) {
		this.compResultList = compResultList;
	}

	public Pager getCompAppPager() {
		return compAppPager;
	}

	public void setCompAppPager(Pager compAppPager) {
		this.compAppPager = compAppPager;
	}

	public Pager getCompResultPager() {
		return compResultPager;
	}

	public void setCompResultPager(Pager compResultPager) {
		this.compResultPager = compResultPager;
	}

	public String getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(String currentPage) {
		this.currentPage = currentPage;
	}

	public String getPageMethod() {
		return pageMethod;
	}

	public void setPageMethod(String pageMethod) {
		this.pageMethod = pageMethod;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public int getLatestCompPageSize() {
		return latestCompPageSize;
	}

	public void setLatestCompPageSize(int latestCompPageSize) {
		this.latestCompPageSize = latestCompPageSize;
	}

	public CompApp getCompApp() {
		return compApp;
	}

	public void setCompApp(CompApp compApp) {
		this.compApp = compApp;
	}

	public int getCompId() {
		return compId;
	}

	public void setCompId(int compId) {
		this.compId = compId;
	}

	public CompResult getCompResult() {
		return compResult;
	}

	public void setCompResult(CompResult compResult) {
		this.compResult = compResult;
	}
	
}
